home *** CD-ROM | disk | FTP | other *** search
- /*
- File: StdIFmIO.cpp
-
- Contains: xxx put contents here xxx
-
- Owned by: Nick Pilch
-
- Copyright:
-
- Change History (most recent first):
-
- <2> .04.1996 NP Change to allow ObjectMaster to parse. No
- code changes.
-
- To Do:
- */
-
- /*
- File: StdIFmIO.cpp
-
- Contains: functions for read/writing standard IconFamily from/to storage units.
- This file is Macintosh-specific.
-
- Owned by: Tantek Çelik, Jens Alfke
-
- Copyright: © 1994 - 1996 by Apple Computer, Inc., all rights reserved.
-
- To Do:
- 1. Ensure that usage of functions to write substreams works (nil prop & val).
- In Progress:
-
- */
-
-
- #ifndef _EXCEPT_
- #include <Except.h>
- #endif
-
- #ifndef _ODDEBUG_
- #include "ODDebug.h"
- #endif
-
- #ifndef _ODMEMORY_
- #include <ODMemory.h>
- #endif
-
- #ifndef SOM_ODStorageUnit_xh
- #include <StorageU.xh>
- #endif
-
- #ifndef SOM_ODStorageUnitView_xh
- #include <SUView.xh>
- #endif
-
- #ifndef SOM_Module_OpenDoc_StdTypes_defined
- #include <StdTypes.xh>
- #endif
-
- #ifndef _STDTYPIO_
- #include "StdTypIO.h"
- #endif
-
- #ifndef _STORUTIL_
- #include <StorUtil.h>
- #endif
-
- #ifndef _TEMPOBJ_
- #include "TempObj.h"
- #endif
-
- #ifndef __ICONS__
- #include <Icons.h>
- #endif
-
- //==============================================================================
- // Constants
- //==============================================================================
-
- static const int kNIconTypes = 8;
- static const ResType kIconType[kNIconTypes]
- = {'ics#','ics4','ics8', 0, 0,'ICN#','icl4','icl8'};
- static const short kIconSize[kNIconTypes]
- = { 64, 128, 256, 512, 1024, 256, 512, 1024};
-
-
- //==============================================================================
- // IconFamily
- //==============================================================================
-
-
- const ODULong kAllMacIconsMask = 0x00E7; // 16x16 and 32x32 / 1,4,8 bits deep
-
- // If there is no value at the passed in prop & val then kODNULL is returned.
- // This is consistent with the other routines in StdTypIO which return pointers.
- // Other StdTypIO routines which actually return the value gotten, WARN if no value
- // is there.
- // The reason is that there may be clients of ODIconFamily which more easily
- // handle the flow of control if it just returns kODNULL instead of THROWing. -Tantek
-
- ODIconFamily
- ODGetIconFamilyProp(Environment* ev, ODStorageUnit* su, ODPropertyName prop,
- ODValueType val, ODULong iconMask)
- {
- if( val == kODIconFamily )
- val = kODIconFamilyMac; // If only kODIconFamily specified, use platform type
-
- if (ODSUExistsThenFocus(ev, su, prop, val))
- {
- iconMask &= kAllMacIconsMask;
-
- ODULong which;
- ODSize pos = sizeof(which);
- StorageUnitGetValue(su, ev, sizeof(which), &which);
- // Which icons have data?
-
- if( (which & iconMask) == 0 )
- return kODNULL;
-
- ODIconFamily iconFamily;
- THROW_IF_ERROR( NewIconSuite((Handle*)&iconFamily) );
-
- ODHandle h=kODNULL; ODVolatile(h);
- TRY{
- for( int i=0; i<kNIconTypes; i++ )
- if( which & (1<<i) ) {
- ODSize size = kIconSize[i];
- pos += size;
- if( iconMask & (1<<i) ) { // Read icon:
- h = ODNewHandle(size);
- StorageUnitGetValue(su, ev,size, ODLockHandle(h));
- ODUnlockHandle(h);
- THROW_IF_ERROR( AddIconToSuite((Handle)h,(Handle)iconFamily,kIconType[i]) );
- h = kODNULL;
- } else
- su->SetOffset(ev,pos); // Don't need this icon
- }
- }CATCH_ALL{
- ODDisposeHandle(h);
- DisposeIconSuite((Handle)iconFamily,kODTrue);
- RERAISE;
- }ENDTRY
-
- return iconFamily;
- }
- else
- return kODNULL;
- }
-
-
- #define SKIPOMPARSE
- #ifdef SKIPOMPARSE
- static const char* const kODIconFamilyBaseString = kODIconFamily ":";
- #else
- static const char* const kODIconFamilyBaseString = "^^^^correct def.^^^^^";
- #endif
-
- void
- ODSetIconFamilyProp(Environment* ev, ODStorageUnit* su, ODPropertyName prop,
- ODValueType val, ODIconFamily iconFamily,
- ODBoolean removeOtherPlatformIcons)
- {
- ODSUForceFocus(ev, su, prop, val);
-
- ODBoolean wholeValue = (prop!=kODNULL || val!=kODNULL);
-
- // See which icons exist in the family:
- ODULong which = 0;
- Handle icon;
- if( iconFamily != kODNULL )
- for( int i=0; i<kNIconTypes; i++ )
- if( kIconType[i] && GetIconFromSuite(&icon,(Handle)iconFamily,kIconType[i])==noErr && icon )
- which |= (1<<i);
-
- if( which==0 && wholeValue)
- {
- // If there are no icons, remove the value:
- su->Remove(ev);
- }
- else
- {
- su->SetOffset(ev,0);
- ODSize size = su->GetSize(ev);
- su->DeleteValue(ev,size);
-
- StorageUnitSetValue(su, ev, sizeof(which), &which);
- for( int i=0; i<kNIconTypes; i++ )
- if( kIconType[i] && GetIconFromSuite(&icon,(Handle)iconFamily,kIconType[i])==noErr && icon )
- {
- TRY{
- ODLockHandle((ODHandle)icon);
- StorageUnitSetValue(su, ev, kIconSize[i], (ODValue)(*icon));
- }CATCH_ALL{
- ODUnlockHandle((ODHandle)icon);
- RERAISE;
- }ENDTRY
- ODUnlockHandle((ODHandle)icon);
- }
- }
-
- if( removeOtherPlatformIcons ) {
- ODULong nValues = su->CountValues(ev);
- ODULong index = 1;
- while( nValues-- != 0 ) {
- su->Focus(ev,kODNULL,kODPosSame, kODNULL,0,index); // Focus to value by index
- TempODValueType type = su->GetType(ev);
- if( strncmp(type,kODIconFamilyBaseString,strlen(kODIconFamilyBaseString)) == 0
- && strcmp(type,val) != 0 )
- su->Remove(ev);
- else
- index++;
- }
- }
- }
-
-